package py.com.fms.exception;

import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;

import org.jboss.seam.core.SeamResourceBundle;

public class CommonException extends Exception {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5330849975588285011L;

	public CommonException() {
	}

	public CommonException(String key) {
		super(getMessageBundle(key,null));
	}
	
	public CommonException(String key, Object...param) {
		super(getMessageBundle(key,param));
	}

	public CommonException(Throwable arg0) {
		super(arg0);
	}

	private static String getMessageBundle(String key, Object...params) {
		String messageTemplate = key;
		ResourceBundle resourceBundle = SeamResourceBundle.getBundle();
        if (resourceBundle != null) {
			try {
			  String bundleMessage = resourceBundle.getString(key);
			  if (bundleMessage != null) {
				  messageTemplate = MessageFormat.format(bundleMessage, params);
			  }
			} catch (MissingResourceException mre) {
			} 			
		}
		return   messageTemplate;
	}

}
